package com.action.Substation;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.entity.Substation;
import com.opensymphony.xwork2.ActionSupport;
import com.service.SubstationService;
import com.service.UnitIntervalService;

public class SubstationAction extends ActionSupport implements SessionAware{
	
	private SubstationService substationService;
	private UnitIntervalService unitIntervalService;
	private Map session;
	public String substationNo;
	private String result;
	public Substation substation;
	
	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public void setUnitIntervalService(UnitIntervalService unitIntervalService) {
		this.unitIntervalService = unitIntervalService;
	}

	public void setSubstationService(SubstationService substationService) {
		this.substationService = substationService;
	}
	
	public String getSubstationNo() {
		return substationNo;
	}

	public void setSubstationNo(String substationNo) {
		this.substationNo = substationNo;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public Substation getSubstation() {
		return substation;
	}

	public void setSubstation(Substation substation) {
		this.substation = substation;
	}

	public String findAuditingSubstation() throws Exception{
		List<Substation> Substationlist = substationService.findAuditingSubstation();
		session.put("substationlist", Substationlist);
		return SUCCESS;
	}
	
	public String addSubstation(){
		substation.setSubstationStatus(1);
		if(substationService.addSubstation(substation))
			return SUCCESS;
		else return INPUT;
	}
	
	public String checkSubstationNoAvailable() throws Exception{
		if(substationService.checkSubstationNoAvailable(substationNo))
			result = "true";
		else result = "false";
		return SUCCESS;
	}
	
	public String substationDetails() throws Exception{
		List<Substation> Substationlist = substationService.substationDetails(substationNo);
		session.put("substationlist", Substationlist);
		return SUCCESS;
	}
	
	public String deleteSubstation() throws Exception{
		Substation substation = (Substation) substationService.findSubstatinByNo(substationNo);
		substationService.deleteSubstation(substation);
		return SUCCESS;
	}
}
